package com.hemh.utils;

import java.time.LocalDateTime;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hemh.service.BookService;
import com.hemh.service.UserService;

/**
 * 
 * @author HeMingHui
 * @since 发送消息的Util类
 * 注册为组件
 */
@Component
public class SendMessageUtils {

	@Resource
	private UserService userService;

	@Resource
	private BookService bookService;

	/**
	 * @author HeMingHui
	 * @since 2020-11-04
	 * @param userNumber
	 * @param bookId
	 * @param nowTime
	 * @param expectReturnTime
	 * @return String
	 * @description 提醒还书的消息
	 */
	public String sendReturnBookMessage(String userNumber, int bookId, LocalDateTime nowTime, LocalDateTime expectReturnTime) {
		String message = "";
		String userName = userService.getUserInfoByUserNumber(userNumber).getUserName();
		String bookName = bookService.getBookInfoById(bookId).getBookName();
		Date endDate = TimeUtils.localDateTimeConvertToDate(nowTime);
		Date startDate = TimeUtils.localDateTimeConvertToDate(expectReturnTime);
		long days = TimeUtils.minuxToDaysByDate(startDate, endDate);
		message = "【消息提醒】 : 尊敬的" + userName + ", 您好。原定于 " + TimeUtils.localDateTimeFormat(expectReturnTime, "yyyy-MM-dd")
				+ " 归还的《" + bookName + "》, 已经超出期限" + days + "天, 请按时归还！";
		return message;
	}

	/**
	 * @author HeMingHui
	 * @since 2020-11-04
	 * @param userNumber
	 * @param bookId
	 * @param nowTime
	 * @param settleMentPrice
	 * @return String
	 * @description 实际还书计费的消息
	 */
	public String sendSettlementPriceMessage(String userNumber, int bookId, LocalDateTime nowTime, float settleMentPrice) {
		String message = "";
		String userName = userService.getUserInfoByUserNumber(userNumber).getUserName();
		String bookName = bookService.getBookInfoById(bookId).getBookName();
		String setmentPriceMsg = "";
		if(settleMentPrice < 0) {
			setmentPriceMsg = "需要补交 "+settleMentPrice;
		}else {
			setmentPriceMsg = "需要退款 "+settleMentPrice;
		}
		message = "【消息提醒】 : 尊敬的" + userName +", 您好。您于 "+TimeUtils.localDateTimeFormat(nowTime, "yyyy-MM-dd")+" 完成归还《"+bookName+"》, " +setmentPriceMsg+" 元";
		return message;
	}
}
